package com.coco.group.service.impl;

import com.coco.group.mapper.GroupBuyHelpMapper;
import com.coco.group.pojo.TbGroupBuyHelp;
import com.coco.group.pojo.TbUser;
import com.coco.group.service.GroupBuyHelpService;
import com.coco.group.service.UserService;
import com.coco.group.vo.GroupHelpAndUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package: com.coco.group.service.impl
 * @Author: 张dy
 * @Date: Created in 2021/7/29 下午 8:02
 */
@Service
public class GroupBuyHelpServiceImpl implements GroupBuyHelpService {

    @Autowired
    private GroupBuyHelpMapper groupBuyHelpMapper;
    @Autowired
    private UserService userService;

    @Override
    public List<GroupHelpAndUser> findBuyHelp(Long recordId) {
        List<GroupHelpAndUser> buyHelpList = groupBuyHelpMapper.findBuyHelp(recordId);
        buyHelpList.forEach(item->{
            Long userId = item.getUserId();
            TbUser u = userService.findOne(userId);
            item.setUser(u);
        });
        return buyHelpList;
    }

    /**
     * 添加参团记录
     * @param groupBuyHelp
     */
    @Override
    public void addGroupBuyHelp(TbGroupBuyHelp groupBuyHelp) {
        groupBuyHelpMapper.addHelp(groupBuyHelp);
    }
}
